package net.yambal.RTM.Method
{
	import flash.events.EventDispatcher;
	
	import net.yambal.RTM.Event.LocationsEvent;
	import net.yambal.RTM.Items.RTMTransaction;
	import net.yambal.RTM.RestWrapper.RestManager;
	import net.yambal.RTM.RestWrapper.RestService;
	import net.yambal.RTM.Utilty.Parser;
	
	[Event(name="get_list", type="net.yambal.RTM.Event.LocationsEvent")]
	public class Locations extends EventDispatcher
	{
		public function Locations()
		{
		}
		
		/**
		 * 場所のリストを取得する
		 **/
		public function getList(api_key:String, shared_secret:String, auth_token:String):void{
			var p:Object= new Object();
			p.api_key = api_key;
			p.auth_token = auth_token;
			
			var RM:RestManager = new RestManager();
			RM.doMethod(RestService.METHOD_LOCATIONS_GET_LIST, p, this.onGetList, this.onFaultGetList, false, shared_secret);
		}
		
		private function onFaultGetList(code:Number, massage:String, ro:Object):void{
			
		}
		
		private function onGetList(result_xml:XML, ro:Object, t:RTMTransaction):void{
			var ret:Array = Parser.LocationXMLListToLocation(result_xml.descendants("location"));
			this.dispatchEvent(new LocationsEvent(LocationsEvent.GET_LIST, ret));
		}

	}
}